package com.changsideal.entity;

import com.amazonaws.services.s3.model.CannedAccessControlList;
import lombok.Getter;

import java.io.File;

/**
 * @ClassName I
 * @Description TODO
 * @Author Create by Chansideal.Haosc
 * @Date 2019/6/19 10:57
 * @Version 1.2
 **/
@Getter
public final class I {
	
	private static final String DEFAULT_BUCKT_NAME = "MY_BUCKET01";
	private static final CannedAccessControlList DEFAULT_FILECATE= CannedAccessControlList.PublicReadWrite;
	
	
    private String bucketName;
    private String[] bucketKey;
    private String metaDataKey;
    private String metaDataValue;
    private String content;
    private String downloadPath;
    private File destFile;
    private CannedAccessControlList fileType;

    private I() {
    }

    private I(IBuilder builder) {
        this.bucketName = builder.bucketName;
        this.bucketKey = builder.bucketKey;
        this.metaDataKey = builder.metaDataKey;
        this.metaDataValue = builder.metaDataValue;
        this.content = builder.content;
        this.downloadPath = builder.downloadPath;
        this.destFile = builder.destFile;
        this.fileType = builder.fileType;
    }

    @Getter
    public static class IBuilder {
        private String bucketName;
        private String[] bucketKey;
        private String metaDataKey;
        private String metaDataValue;
        private String content;
        private String downloadPath;
        private File destFile;
        private CannedAccessControlList fileType;

        public IBuilder() {
        }

        public IBuilder setBucketName(String bucketName) {
            this.bucketName = bucketName;
            return this;
        }

        public IBuilder setBucketKey(String[] bucketKey) {
            this.bucketKey = bucketKey;
            return this;
        }

        public IBuilder setMetaDataKey(String metaDataKey) {
            this.metaDataKey = metaDataKey;
            return this;
        }

        public IBuilder setMetaDataValue(String metaDataValue) {
            this.metaDataValue = metaDataValue;
            return this;
        }

        public IBuilder setContent(String content) {
            this.content = content;
            return this;
        }

        public IBuilder setDownloadPath(String downloadPath) {
            this.downloadPath = downloadPath;
            return this;
        }

        public IBuilder setDestFile(File destFile) {
            this.destFile = destFile;
            return this;
        }

        public IBuilder setFileType(CannedAccessControlList fileType) {
            this.fileType = fileType;
            return this;
        }


        public I build() {
            return new I(this);
        }
    }
    
    public static I.IBuilder Builder(){
    	return new I.IBuilder();
    }
//    private String bucketKey;
//    private String metaDataKey;
//    private String metaDataValue;
//    private String content;
//    private String downloadPath;
//    private File destFile;
//    private CannedAccessControlList fileType;

    public static I buildSimple(String downloadPath, File destFile, String... bucketKeys) {
    	return buildSimple(DEFAULT_BUCKT_NAME, downloadPath, destFile, "", DEFAULT_FILECATE, null, null, bucketKeys);
    }
    
    public static I buildSimple(String bucketName, String downloadPath,
    							File destFile, String content, 
    							CannedAccessControlList cannd, String metaDataKey, 
    							String metaDataValue, String... bucketKeys) {
    	
    	return Builder().setBucketKey(bucketKeys)
    			.setBucketName(bucketName)
    			.setDownloadPath(downloadPath)
    			.setDestFile(destFile)
    			.setContent(content)
    			.setFileType(cannd)
    			.setMetaDataKey(metaDataKey)
    			.setMetaDataValue(metaDataValue).build();
    	
    }

    @Override
    public String toString() {
        return "I{" +
                "bucketName='" + bucketName + '\'' +
                ", bucketKey='" + bucketKey + '\'' +
                ", metaDataKey='" + metaDataKey + '\'' +
                ", metaDataValue='" + metaDataValue + '\'' +
                ", content='" + content + '\'' +
                ", downloadPath='" + downloadPath + '\'' +
                '}';
    }
}
